	pagesInit();
	window.ontouchstart = function (e) {
	    var longTapDelay = 750;
	    window.longTapTouch = {};
	    window.longTapTouch.begin = new Date;
	    window.longTapTimeout = setTimeout(function () {
	        if (window.longTapTouch.begin) {
	            var event = document.createEvent("Events");
	            var bubbles = true;
	            event.initEvent("longTap", bubbles, true, null, null, null, null, null, null, null, null, null, null, null, null);
	            event.data = undefined;
	            e.target.dispatchEvent(event);
	        }
	        window.longTapTouch = {};
	    }, longTapDelay);
	    window.longTap = false;
	}
	window.ontouchmove = function(e){		
        clearTimeout(window.longTapTimeout);
	}
	window.ontouchend = function (e) {
	    if ((new Date) - window.longTapTouch.begin < 750) {
	        clearTimeout(window.longTapTimeout);
	    }
	}
	function callNative(e,type,that){
		switch(type){
			case 'bookmark':
				that.style.background = "url(./images/bookmarkClick.png) top left no-repeat";
				window.timeOut = setTimeout(function(){that.style.background = "url(./images/bookmark.png) top left no-repeat";orangeHomeLink.viewBookmark();},300);
				break;
			case 'history': 				
				that.style.background = "url(./images/historyClick.png) top left no-repeat";
				window.timeOut = setTimeout(function(){that.style.background = "url(./images/history.png) top left no-repeat";orangeHomeLink.viewHistory();},300);			
				break;
			case 'readlist':
				that.style.background = "url(./images/readlistClick.png) top left no-repeat";
				window.timeOut = setTimeout(function(){that.style.background = "url(./images/readlist.png) top left no-repeat";orangeHomeLink.viewReading();},300);
				break;
			default:
			    console.log("unexpected type caughted!");
		}
	}
	function cancel(e, that){
		clearTimeout(window.timeOut);
		var background = that.style.background.split("Click").join("");
		that.style.background = background;
	}
	
	// add font color effect when clicked.
	function carousels(e) {
	    e.preventDefault();
	    if (window.longTap) {
	        window.longTap = false;
	        return;
	    }
	    var target = e.target;
	    var href;
	    var domNode;
		if(target.parentNode.className == "mvItem"){
			var tmpNode = target.parentNode;
			tmpNode.style.backgroundColor="#2eaccc";
			tmpNode.style.opacity="0.5";
			location.href = tmpNode.getAttribute("url");
		}else if(target.className=="mvItem"){
			target.style.backgroundColor="#2eaccc";
			target.style.opacity="0.5";
			location.href = target.getAttribute("url");
		}
	    else if (!target.id) {
	        if (target.tagName == "IMG") {
	            if (target.getAttribute("class") == "blogimg") {
	                href = target.parentNode.href;
	            } else {
	                href = target.parentNode.getAttribute("href");
	            }
	            target.style.webkitBoxShadow = "0px 0px 2px 2px #2eaccc";
	            domNode = target;
	        }
	        setTimeout(function () {
	            if (domNode) domNode.style.webkitBoxShadow = "";
	            if (href) {
	                location.href = href;
	            }
	            href = undefined;
	        }, 100);
	    }
	    return false;
	}
	document.body.onclick = carousels;

	function pagesInit() {
	    var imgRes = {
	        "http://3g.sina.com.cn/": "./images/sina.png",
	        "http://www.douban.com/": "./images/douban.png",
	        "http://3g.163.com/book": "./images/neteasy.png",
	        "http://www.36kr.com/": "./images/36.png",
	        "http://g.xxsy.net/": "./images/shuyuan.png",
	        "http://www.gfan.com/juhe": "./images/jifeng.png",
	        "http://www.kaixin001.com/": "./images/kaixin.png",
	        "http://www.yuedu123.com/": "./images/123.png",
			"http://i.ifeng.com/":"./images/fenghuang.png"
	    };
	    window.page2 = {
	        el: document.getElementsByClassName("page")[0],
	        init: function () {
	            var linkInfo, url, imgSrc, title, base64Image;
				var positions = this.linkPositions();
	            for (var i = 0; i < positions.length; i++) {
	                linkInfo = JSON.parse(orangeHomeLink.getLinkInfo(positions[i]));
	                if (linkInfo) {
	                    url = linkInfo.url;
	                    imgSrc = imgRes[url] ? imgRes[url] : ("data:image/png;base64," + orangeHomeLink.getBase64Image(positions[i]));
	                    if ((!imgRes[url]) && (imgSrc.length<50)) {
	                        imgSrc = "./images/SDdefault.png";
	                    }
	                    title = linkInfo.title;
	                } 					
	                this.switchIt(imgSrc, url, title, true);	   
	            }
				this.switchIt("images/AddPlus.png", "javascript:orangeHomeLink.addHomeLink();", String.fromCharCode(28155,21152,39057,36947), true);
	            return true;
	        },
	        switchIt: function (imgSrc, url, title, showIt, element) {
				var img2 = document.createElement("img");
				img2.src = imgSrc;
				img2.style.height = "62px";		
								
				var a = document.createElement("a");
				a.href = url;
				a.setAttribute("title", title);				
				a.appendChild(img2);
				if(title!=String.fromCharCode(28155,21152,39057,36947)){					
					var img = document.createElement("img");
					img.src = "./images/back.png";
					img.style.zIndex="10";	
					a.appendChild(img);
				}
				
				var iconImage = document.createElement("div");
				title!=String.fromCharCode(28155,21152,39057,36947) ? (iconImage.setAttribute("class","iconImage")):(iconImage.setAttribute("class","add"));
				iconImage.appendChild(a);
				
				var iconContainer = document.createElement("div");
				iconContainer.setAttribute("class","iconContainer");
				iconContainer.appendChild(iconImage);
				
				var span = document.createElement("span");
				span.setAttribute("href", url);
				span.innerHTML = title;
				
				iconContainer.appendChild(span);
				if(element){
					document.getElementById("urlIcons").insertBefore(iconContainer, element);
				}else{
					document.getElementById("urlIcons").appendChild(iconContainer);
				}
			},
	        linkPositions: function () {
	            if (orangeHomeLink.getHomeLinkPositions) {
					var positionArray = orangeHomeLink.getHomeLinkPositions().split(";");
					positionArray.pop();
	                return positionArray;
	            } else {
	                return false;
	            }
	        }
	    };
		window.page3 = function(){
			var mvItems = document.getElementsByClassName("mvItem");
			var name_url = eval(orangeHomeLink.getMostVisited());
			for(var i=0; i<mvItems.length; i++){
				var spans = mvItems[i].getElementsByTagName("span");
				if(name_url && name_url[i]){
					spans[0].innerHTML = name_url[i].title;
					spans[1].innerHTML = name_url[i].url;
					mvItems[i].setAttribute("url",name_url[i].url);
				}
				else{
					spans[0].innerHTML = "空白页";
					spans[0].className = "blank";
					spans[1].style.display = "none";
					mvItems[i].setAttribute("url","javascript:void(0)");
				}
			}
		}
		page3();
		page2.init();		
	};

	//wait for the call by native code.
	function managehomelink(json) {
		history.go(0);
	}
	//waiting for longtap event firing.
	window.addEventListener("longTap", function (e) {
	    e.stopPropagation();
	    window.longTap = true;
	    if (!e.target.id && (e.target.tagName == "IMG") && e.target.className!="arrow") {
	        if (!(/javascript/i.test(e.target.parentNode.href))) {
	            var pos = e.target.parentNode.getAttribute("pos");
	            var href = e.target.parentNode.href;
	            var title = e.target.parentNode.getAttribute("title");
	            var str = '{"url":"' + href + '", "title":"' + title + '"}';
	            orangeHomeLink.contextMenu(str);
				window.targetDomNode = e.target.parentNode.parentNode.parentNode;
	        }
	    }
	}, false);
	//change css style according to window size
	function setStyle(orientation) {
	   try {
			var width = window.innerWidth;
			var counter = 0;
			var interval = setInterval(function(){
				if(window.innerWidth != width){
					setTimeout(function(){						
						window.orientationChange();
					},200);
					clearInterval(interval);
				}
				if((++counter)>10){
					clearInterval(interval);
				}				
			},100);
	    }catch (e) {
	        console.log("Error occured in setStyle, the message is :" + e.message);
			location.reload();
	    }
	}
	function onConfigurationChanged(orientation) {
		//document.getElementById("carousel").style.visibility = "hidden";
		setStyle(orientation);
	}